<?php

namespace Services\Commands;

use Services\RabbitMq\RabbitMqManager;
use Services\RabbitMq\RabbitMqSender;

class CommandService
{
    private $manager;

    private $sender;

    public function __construct()
    {
        $this->manager = RabbitMqManager::getInstance('194.87.110.114', 5672, 'guest', 'guest');
        $this->sender = new RabbitMqSender('194.87.110.114', 5672, 'guest', 'guest', $this->manager);
        $this->manager->createQueue('interact');
        $this->manager->createQueue('watchers');
    }

    public function interact(int $userId, string $connectionName, string $sessionType, string $command, $parameters, $queue)
    {
        $this->sender->changeQueue($queue);
        $this->sender->sendMessage(json_encode([
            'user' => $userId,
            'connection' => $connectionName,
            'command' => $command,
            'sessionType' => $sessionType,
            'parameters' => $parameters,
        ]), $queue);
    }
}
